<script setup>

import NavBar from "@/components/common/navbar/NavBar.vue";
import {logout} from "@/network/user";
import {showSuccessToast} from "vant";
import {useRouter} from "vue-router";
import {useStore} from "vuex";

const store = useStore()
const router = useRouter()
const toLogout = () => {
  logout().then(res => {
    if (res.status === 204) {
      showSuccessToast('退出成功');
      // 清除Token 信息
      window.localStorage.setItem('token', '');
      // 修改状态管理里的登录状态
      store.commit('setIsLogin', false)
      // 刷新购物车列表
      store.state.cartCount = 0
      // 推出成功跳转到登录页面
      setTimeout(() => {
        router.push({path: "/login"})
      }, 500)

    }
  })
}
</script>

<template>
  <div>
    <nav-bar class="nav-bar">
      <template v-slot:default>
        账号管理
      </template>
    </nav-bar>
    <div>
      <van-button block color="#44BA80" round style="margin-top: 100px" @click="toLogout">退出账号</van-button>
    </div>
  </div>
</template>

<style lang="scss" scoped>

</style>